import { number } from "echarts";
import http from "./httpInstance";

export interface DirectionStatisticsReqDto {
  beginTime?: string;
  endTime?: string;
  pageNo?: number;
  pageSize?: number;
}
export interface DirectionStatisticsResDto {
  proportion: string; //方向
  direction: string; // 方向所占比例
}
export type DirectionStatisticsPieData = EchartsSeriseData &
  DirectionStatisticsResDto;

// 事件方向统计
export const directionStatisticsService = (
  data: DirectionStatisticsReqDto
): Promise<ResponseResult<DirectionStatisticsPieData[]>> => {
  return http({
    method: "post",
    data,
    url: "/orgmanager-web/trafficStatistic/directionStatistics",
  });
};

export interface LaneNoStatisticsResDto {
  laneNoName: string; //进口道
  number: string; // 数量
}
export type LaneNoStatisticsPieData = EchartsSeriseData &
  LaneNoStatisticsResDto;
// 事件进口道统计
export const laneNoStatisticsService = (
  data: DirectionStatisticsReqDto
): Promise<ResponseResult<PageResult<LaneNoStatisticsPieData[]>>> => {
  return http({
    method: "post",
    url: "/orgmanager-web/trafficStatistic/laneNoStatistics",
    data,
  });
};

export interface QueryEventReqDto {
  pageNo: number;
  pageSize: number;
  plateNumber: string;
}
export interface QueryEventResDto {
  crossingName: number; // 路口名称
  happenTime: number; // 发生时间
  laneDirection: string; //车道方向
  laneNo: string; // 车道号
  plateNumber: string; //车牌号码
}

// 查询交通统计事件 ---- 根据车牌查询
export const queryEventService = (
  data: QueryEventReqDto
): Promise<ResponseResult<PageResult<LaneNoStatisticsPieData[]>>> => {
  return http({
    method: "post",
    data,
    url: "/orgmanager-web/trafficStatistic/queryEvent",
  });
};

export interface IntersectionResDto {
  arrivalFlow: string; // 到达流量
  crossingLevel: string; // 路口运行状况等级
  crossingName: string; //路口名称
  delay: string; // 平均延误
  happenTime: string; //发生时间
  queueLen: string; // 排队长度
  vehicleSpeed: string; //车速
}

// 路口指标和运行等级
export const intersectionIndicatorsService = (
  data: IntersectionReqDto
): Promise<ResponseResult<PageResult<IntersectionResDto[]>>> => {
  return http({
    method: "post",
    data,
    url: "/orgmanager-web/trafficStatistic/intersectionIndicators",
  });
};

export interface IntersectionReqDto {
  crossingName?: string; // 路口名称
  pageNo?: number; //
  pageSize?: number; //
  beginTime?: string; //开始时间
  endTime?: string; //结束时间
}

export interface PeakHoursResDto {
  arrivalFlow: string; // 到达流量
  crossingLevel: string; // 路口运行状况等级
  crossingName: string; // 路口名称
  delay: string; // 平均延误
  stoppingTimes: string; // 平均停车次数
  time: string; // 发生时间段
  vehicleSpeed: string; // 车速
}

// 高峰时段指标和运行等级
export const peakHoursIndicatorsService = (
  data: IntersectionReqDto
): Promise<ResponseResult<PageResult<PeakHoursResDto[]>>> => {
  return http({
    method: "post",
    data,
    url: "/orgmanager-web/trafficStatistic/peakHoursIndicators",
  });
};

export interface PageReqDto {
  pageNo: number; // 开始时间
  pageSize: number; // 路口名称
}
export interface CongestionResDto {
  congestionLevel: string; // 拥堵级别
  entranceRoad: string; // 进口道(路口名称+车道方向+车道号)
  happenTime: string; // 发生时间
  queueLen: string; // 排队长度
}

// 查询拥堵状态
export const queryCongestionService = (
  data: PageReqDto
): Promise<ResponseResult<PageResult<CongestionResDto[]>>> => {
  return http({
    method: "post",
    data,
    url: "/orgmanager-web/trafficStatistic/queryCongestion",
  });
};

// 事件数量统计
export const eventNumStatisticsService = (
  data: DirectionStatisticsReqDto
): Promise<ResponseResult<number>> => {
  return http({
    method: "post",
    data,
    url: "/orgmanager-web/trafficStatistic/eventNumStatistics",
  });
};

export interface EntranceCongestionReqDto{
  entranceRoad:string //进口道(路口名称+车道方向+车道号)
}
export interface EntranceCongestionResDto{
  queueLen:	number;
  time:	number
}
// 查询某个进口道24小时拥堵数据
export const queryEntranceCongestionService = (
  data: EntranceCongestionReqDto
): Promise<ResponseResult<EntranceCongestionResDto[]>> => {
  return http({
    method: "post",
    data,
    url: "/orgmanager-web/trafficStatistic/queryEntranceCongestion",
  });
};

export interface ConfigDto {
  arrivalFlow?: string;
  delay?: string;
  queryFrequency?: string;
  queueLen?: string;
  vehicleSpeed?: string;
}

// 查询各个配置项信息
export const queryFrequencyService = (): Promise<ResponseResult<ConfigDto>> => {
  return http({
    method: "get",
    url: "/orgmanager-web/trafficStatistic/queryFrequency",
  });
};

export default {
  queryEntranceCongestionService,
  eventNumStatisticsService,
  queryFrequencyService,
  peakHoursIndicatorsService,
  intersectionIndicatorsService,
  queryEventService,
  directionStatisticsService,
  laneNoStatisticsService,
};
